// ignore_for_file: dangling_library_doc_comments, slash_for_doc_comments
/*** 
 * @Author: Zhong
 * @Date: 2025-07-11 11:30:49
 * @LastEditors: Zhong zhongxiaodong@eenet.com
 * @LastEditTime: 2025-07-15 14:31:32
 * @FilePath: /wan_android_flutter/lib/main.dart
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wan_android_flutter/common_code/configs/app_color_config.dart';

import 'common_code/tabbar/bottom_nav_tabbar.dart';
import 'common_code/utils/tools.dart';
import 'common_code/wrapper/shared_preferences_wrapper/shared_preferences_wrapper.dart';
import 'module_code/login/pages/login_page.dart';
import 'common_code/configs/app_router_config.dart';

void main() async {
  // 确保 Flutter 框架初始化完成
  WidgetsFlutterBinding.ensureInitialized();
  //初始化EasyLoading
  configLoading();
  //初始化SharedPreferences
  await SharedPreferencesWrapper.init();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return GetMaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            appBarTheme: AppBarTheme(
              centerTitle: true,
              backgroundColor: Colors.blue,
              foregroundColor: Colors.white,
            ), //统一配置标题居中
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
            scaffoldBackgroundColor: AppColorConfig.backgroundColor,
          ),
          builder: EasyLoading.init(),
          home: child,
          getPages: AppRouterConfig.routes,
          // onGenerateRoute: (settings) => Routers.onGenerateRoute(settings),
        );
      },
      child: Tools.isUserLogin() ? BottomNavTabbar() : LoginPage(),
    );
  }
}

// 配置EasyLoading
void configLoading() {
  EasyLoading.instance
    ..displayDuration = const Duration(milliseconds: 2000)
    ..indicatorType = EasyLoadingIndicatorType.fadingCircle
    ..loadingStyle = EasyLoadingStyle.dark
    ..indicatorSize = 45.0
    ..radius = 10.0
    ..progressColor = Colors.yellow
    ..backgroundColor = Colors.green
    ..indicatorColor = Colors.yellow
    ..textColor = Colors.yellow
    ..maskColor = Colors.blue.withOpacity(0.5)
    ..userInteractions = false
    ..dismissOnTap = false;
}
